package com.shiliao.app.activity.interlocution.dialog;

import android.content.Context;
import android.view.View;

import com.shiliao.app.R;
import com.shiliao.app.activity.interlocution.entity.InterlocutionEntity;
import com.yimei.framework.ui.recyclerview.CommonAdapter;
import com.yimei.framework.ui.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * Created by yinzhiqiang on 2017/12/8.
 */

public class SimilarQuestionAdapter extends CommonAdapter<InterlocutionEntity> {
    private CheckQuestion checkQuestion;
    private int checkId = -1;

    public SimilarQuestionAdapter(Context context, int layoutId, List datas, CheckQuestion checkQuestion) {
        super(context, layoutId, datas);
        this.checkQuestion = checkQuestion;
    }

    @Override
    protected void convert(final ViewHolder holder, final InterlocutionEntity entity, final int position) {
        holder.setText(R.id.tv_similar_question, entity.content);
        holder.setBackgroundRes(R.id.tv_similar_question, R.color.white);
        if (checkId == position && checkId != -1) {
            holder.setBackgroundRes(R.id.tv_similar_question, R.color.white);
        }
        holder.setOnClickListener(R.id.tv_similar_question, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (checkId != position) {
                    holder.setBackgroundRes(R.id.tv_similar_question, R.color.color_bird_repay);
                    notifyItemChanged(checkId);
                    checkId = position;
                }
                checkQuestion.clickCheck(entity.question_id);
            }
        });

    }

    public interface CheckQuestion {
        void clickCheck(String position);
    }
}
